Skip to content

Fix ORCA choosing wrong column type for CTAS with UNION ALL (#1431)#1645

Merged
yjhjstz merged 3 commits intoapache:mainfrom
yjhjstz:fix_union_type
Apr 1, 2026
Merged

Fix ORCA choosing wrong column type for CTAS with UNION ALL (#1431)#1645
yjhjstz merged 3 commits intoapache:mainfrom
yjhjstz:fix_union_type

Conversation

@yjhjstz
Copy link
Copy Markdown
Member

@yjhjstz yjhjstz commented Mar 27, 2026

When removing redundant Result nodes in the ORCA post-processing, push_down_expr_mutator replaces parent Var nodes with child expressions. It already propagates typmod for Const child expressions, but missed the case where the child expression is also a Var. This caused the correctly resolved common typmod (e.g. -1 for varchar without length) to be overwritten by the child's original typmod (e.g. varchar(1)), resulting in wrong column types in the created table.

Fixes #1431

What does this PR do?

Type of Change

  • Bug fix (non-breaking change)
  • New feature (non-breaking change)
  • Breaking change (fix or feature with breaking changes)
  • Documentation update

Breaking Changes

Test Plan

  • Unit tests added/updated
  • Integration tests added/updated
  • Passed make installcheck
  • Passed make -C src/test installcheck-cbdb-parallel

Impact

Performance:

User-facing changes:

Dependencies:

Checklist

Additional Context

CI Skip Instructions


yjhjstz added 2 commits March 27, 2026 16:43
)

When removing redundant Result nodes in the ORCA post-processing,
push_down_expr_mutator replaces parent Var nodes with child expressions.
It already propagates typmod for Const child expressions, but missed the
case where the child expression is also a Var. This caused the correctly
resolved common typmod (e.g. -1 for varchar without length) to be
overwritten by the child's original typmod (e.g. varchar(1)), resulting
in wrong column types in the created table.
Verify that ORCA produces the correct column type (character varying
without length limit) when creating a table from UNION ALL of branches
with different varchar lengths.
Copy link
Copy Markdown
Contributor

@my-ship-it my-ship-it left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Nice catch and clean fix! 👍

@yjhjstz yjhjstz requested a review from reshke March 30, 2026 12:50
@reshke
Copy link
Copy Markdown
Contributor

reshke commented Apr 1, 2026

LGTM

@yjhjstz yjhjstz merged commit 9548636 into apache:main Apr 1, 2026
41 checks passed
@yjhjstz yjhjstz deleted the fix_union_type branch April 1, 2026 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Orca chooses the wrong column type for CTAS

3 participants